angular.module('casher', ['ionic', 'angular-meteor','angularMoment','ngCordova','common',
  'global','casher.controllers','chat'
])
.run(function($rootScope, $ionicPlatform,amMoment,StatusBarService,BackButtonService) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }

    StatusBarService.setStyle();
    BackButtonService.registerBackButtonAction();
  });
  amMoment.changeLocale('zh-cn');

  $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options) {
    if ($rootScope.currentUser===null) {
      $ionicPopup.confirm({
        title: '登录超时',
        template: '请您重新登录',
        cancelText: '取消',
        okText: '确定'
      }).then(function (res) {
        setTimeout(function () {
          window.location.href='index.html';
        }, 500);

      });
    }
  });
})

.config(function($stateProvider, $urlRouterProvider,$ionicConfigProvider) {
  $ionicConfigProvider.backButton.text('');
  $ionicConfigProvider.backButton.previousTitleText(false);

  $ionicConfigProvider.tabs.style('standard');
  $ionicConfigProvider.tabs.position('bottom');

  $stateProvider
    .state('app', {
    url: '/',
    abstract: true,
    templateUrl: 'templates/common/menu.html',
    controller: 'AppCtrl'
  })

  .state('app.home', {
    url: 'home',
    views: {
      'menuContent': {
        templateUrl: 'templates/casher/tab-home.html',
        controller: 'HomeCtrl'
      }
    }
  })

    // 销售单详情
    .state('app.sale-order-detail', {
      url: 'sale/order-:_id',
      views: {
        'menuContent': {
          templateUrl: 'templates/casher/sale/order-detail.html',
          controller: 'SaleOrderDetailCtrl'
        }
      }
    });
  $urlRouterProvider.otherwise('/home');
});
